package com.eliza.kotlin.design.creation.factory.before_0

/**
 * @version v1.0
 * @ClassName: CoffeeStore
 * @Description: TODO(一句话描述该类的功能)
 * @Author: 黑马程序员
 */
/**
 * Coffee store
 * Store  直接创建对象
 * @constructor Create empty Coffee store
 */
private class CoffeeStore {
    fun orderCoffee(type: String): Coffee {
        //声明Coffee类型的变量，根据不同类型创建不同的coffee子类对象
        var coffee: Coffee? = null
        coffee = if ("american" == type) {
            AmericanCoffee()
        } else if ("latte" == type) {
            LatteCoffee()
        } else {
            throw RuntimeException("对不起，您所点的咖啡没有")
        }
        //加配料
        coffee.addMilk()
        coffee.addsugar()
        return coffee
    }
}

object Client {
    @JvmStatic
    fun main(args: Array<String>) {
        //1,创建咖啡店类
        val store = CoffeeStore()
        //2,点咖啡
        val coffee = store.orderCoffee("american")
        println(coffee.name)
    }
}